'use strict';

module.exports = () => {
  return async function(ctx, next) {
    let token = '';
    if (ctx.headers.authorization) {
      token = ctx.headers.authorization;
    }

    if (!token) {
      ctx.status = 401;
      ctx.body = {
        success: false,
        error_msg: '错误的 accessToken',
      };
      return;
    }

    if (token !== 'admin') {
      ctx.status = 401;
      ctx.body = {
        success: false,
        error_msg: '错误的 accessToken',
      };
      return;
    }

    await next();
  }
}